#!/usr/bin/env bash

set -ex

# 系统及防火墙设置
apt-get install -y zsh curl ufw
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
ufw allow 22
ufw allow 80
ufw allow 443
ufw allow 465
ufw default deny incoming
ufw default allow outgoing
ufw status verbose
ufw -f enable

# 安装过程中选择默认选项
export DEBIAN_FRONTEND=noninteractive

# 更新Nginx源
add-apt-repository ppa:nginx/stable
apt-get update
# 依赖
apt-get install -y git supervisor nginx python3-pip mongodb
pip3 install gevent gunicorn pymysql setuptools django-ranged-response django-simple-captcha djongo gevent gunicorn pymongo




# 服务器
#  nginx
rm -f /etc/nginx/sites-enabled/default
rm -f /etc/nginx/sites-available/default
cp nginx.conf /etc/nginx/sites-enabled/django_blog
# supervisor
cp ~/python/django_blog/supervisor.conf /etc/supervisor/conf.d/supervisor.conf


chmod -R o+rwx ~/python/django_blog/




# 初始化
cd ~/python/
python3 manage.py migrate
python manage.py collectstatic



# 重启服务器
service supervisor restart
service nginx restart

echo 'succsss'

